import CodeEditor from "@/components/codemirror/CodeEditor";
import { Form, Input } from "antd";
import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
import { subjectNodePreviewById } from '@/api/sharing/dataSubject'


const ResponseView = forwardRef(({ style, subjectDetail }, ref) => {
  const [form] = Form.useForm()
  const [value, setValue] = useState('')

  useImperativeHandle(ref, () => ({
    validateFields: form.validateFields,
    value: value
  }))

  useEffect(() => {
    subjectNodePreviewById(subjectDetail.id).then(res => {
      setValue(res?.result || '')
    })
  }, [])

  return <div style={{ ...style, width: '60%', margin: '0 auto' }}>
    <CodeEditor value={value} onChange={setValue} height={'300px'} lang="json" readOnly />
  </div>
})






export default ResponseView